import routerConfig from '@/../config/router.config';

const reorder = (list, startIndex, endIndex) => {
    const result = Array.from(list);
    const [removed] = result.splice(startIndex, 1);
    result.splice(endIndex, 0, removed);

    return result;
};

const move = (source, destination, droppableSource, droppableDestination) => {
    const sourceClone = Array.from(source);
    const destClone = Array.from(destination);
    const [removed] = sourceClone.splice(droppableSource.dragIndex, 1);

    destClone.splice(droppableDestination.dragIndex, 0, removed);

    const result = {};
    result[droppableSource.dropIndex] = sourceClone;
    result[droppableDestination.dropIndex] = destClone;

    return result;
};
/**
 * 通过code 查找对应的path
 */
const findCodeFn = code => {
    let result = {};
    const findCode = (r, c) => {
        r.forEach(item => {
            if (item.routes) {
                findCode(item.routes, c);
            }
        });
        const res = r.find(item => item.code === c && item.thirdLevel);
        if (res) result = res;
    };
    findCode(routerConfig, code);
    return result;
};
/**
 * 检验是否为false
 */
const isNone = currentValue => currentValue === false;

export { reorder, move, findCodeFn, isNone };
